package gui;

import controller.ATM;
import data.BankDatabase;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * @author Besitzer
 * Represents the screen of the ATM
 */
public class Screen extends JFrame{

	public static final String WELCOME = "welcome";
	public static final String ADMMENU = "adminmenu";
	public static final String ADMCREATE = "admincreate";
	public static final String ADMEDIT = "adminedit";
	public static final String ADMDELETE = "admindelete";
	public static final String ADMVIEW = "adminview";
	public static final String CHOICEACC = "choiceaccount";
	public static final String ACCMENU = "accountmenu";
	public static final String ACCDEPOSIT = "accountdeposit";
	public static final String ACCWITHDRAWAL = "accountwithdrawal";
	public static final String ACCINTERESTRATE = "accountinterestrate";
	public static final String ACCACCOUNTINFO = "accountbalanceinquiry";
	public static final String USERMENU = "usermenu";
	public static final String USERMENUADD = "usermenuadd";
	public static final String USERMENUDELETE = "usermenudelete";
	public static final String USERMENUVIEWACC = "usermenuviewacc";
	public static final String USERMENUCHOICEACC = "usermenuchoiceacc";
	
	private JPanel contentPane;
	private Welcome welcome;
	private AdmMenu adminmenu;
	private AdmCreate admincreate;
	private AdmEdit adminedit;
	private AdmDelete admindelete;
	private AdmView adminview;
	private ChoiceAcc choiceacc;
	private AccMenu accountmenu;
	private AccDeposit accountdeposit;
	private AccWithdrawal accountwithdrawal;
	private AccInterestRate accountinterestrate;
	private AccAccountInfo accountAccountInfo;
	private UserMenu usermenu;
	private UserMenuAdd usermenuadd;
	private UserMenuDelete usermenudelete;
	private UserMenuViewAcc usermenuviewacc;
	
	private BankDatabase bdb;
	private ATM atm;
	
	private CardLayout cardlay;
	
	public Screen(ATM atm){
		
		this.atm = atm;

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setTitle("Automated Teller Machine");
		setBounds(0, 0, 550, 400);
		setLocation(350, 200);

		contentPane = new JPanel();
		setContentPane(contentPane);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new CardLayout());

		welcome = new Welcome();
		contentPane.add(welcome, WELCOME);
		cardlay = (CardLayout) getContentPane().getLayout();
	}
	
	public void initGUIs(){

		adminmenu = new AdmMenu();
		contentPane.add(adminmenu, ADMMENU);

		admincreate = new AdmCreate();
		contentPane.add(admincreate, ADMCREATE);
		
		admindelete = new AdmDelete(bdb, this);
		contentPane.add(admindelete, ADMDELETE);
		
		adminedit = new AdmEdit(this);
		contentPane.add(adminedit, ADMEDIT);
		
		adminview = new AdmView(bdb, this);
		contentPane.add(adminview, ADMVIEW);

		accountmenu = new AccMenu();
		contentPane.add(accountmenu, ACCMENU);

		accountdeposit = new AccDeposit();
		contentPane.add(accountdeposit, ACCDEPOSIT);

		accountwithdrawal = new AccWithdrawal();
		contentPane.add(accountwithdrawal, ACCWITHDRAWAL);

		accountinterestrate = new AccInterestRate();
		contentPane.add(accountinterestrate, ACCINTERESTRATE);

		accountAccountInfo = new AccAccountInfo();
		contentPane.add(accountAccountInfo, ACCACCOUNTINFO);

		usermenu = new UserMenu();
		contentPane.add(usermenu, USERMENU);

		usermenuadd = new UserMenuAdd();
		contentPane.add(usermenuadd, USERMENUADD);

		usermenuviewacc = new UserMenuViewAcc();
		contentPane.add(usermenuviewacc, USERMENUVIEWACC);

	}
	
	public void addAdminDelete(ATM atm) {
		this.bdb = atm.getClassBankDatabase();
		admindelete = new AdmDelete(bdb, this);
		contentPane.add(admindelete, ADMDELETE);
	}
	
	public void addAdminView(ATM atm){
		this.bdb = atm.getClassBankDatabase();
		adminview = new AdmView(bdb, this);
		contentPane.add(adminview, ADMVIEW);
	}
	
	public void addUserMenuDelete(ATM atm){
		this.bdb = atm.getClassBankDatabase();
		usermenudelete = new UserMenuDelete(bdb,this);
		contentPane.add(usermenudelete, USERMENUDELETE);
	}
	
	public void addChoiceAcc (ATM atm) {
		this.bdb = atm.getClassBankDatabase();
		choiceacc = new ChoiceAcc(bdb, this);
		contentPane.add(choiceacc, CHOICEACC);
	}
	
	public Welcome getWelcome() {
		return welcome;
	}
	
	public AdmMenu getAdmMenu(){
		return adminmenu;
	}
	
	public AdmCreate getAdmCreate(){
		return admincreate;
	}
	
	public AdmEdit getAdmEdit() {
		return adminedit;
	}
	
	public AdmDelete getAdmDelete(){
		return admindelete;
	}
	
	public AdmView getAdmView(){
		return adminview;
	}
	
	public ChoiceAcc getChoiceAcc(){
		return choiceacc;
	}
	
	public AccMenu getAccMenu(){
		return accountmenu;
	} 
	
	public AccDeposit getAccDeposit(){
		return accountdeposit;
	}
	
	public AccWithdrawal getAccWithdrawal(){
		return accountwithdrawal;
	}
	
	public AccInterestRate getAccInterestRate(){
		return accountinterestrate;
	}
	
	public AccAccountInfo getAccAccountInfo(){
		return accountAccountInfo;
	}
	
	public UserMenu getUserMenu(){
		return usermenu;
	}
	
	public UserMenuAdd getUserMenuAdd(){
		return usermenuadd;
	}
	
	public UserMenuDelete getUserMenuDelete(){
		return usermenudelete;
	}
	
	public UserMenuViewAcc getUserMenuViewAcc(){
		return usermenuviewacc;
	}
	
	public ATM getClassATM() {
		return atm;
	}

	public void show(String card) {
		cardlay.show(this.getContentPane(), card);
	}
	
} // end class Screen